home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 23
/
Aminet 23 (1998)(GTI - Schatztruhe)[!][Feb 1998].iso
/
Aminet
/
text
/
misc
/
micronote.lha
/
オNote
/
Source
/
オNote.c
< prev
Wrap
C/C++ Source or Header
|
1996-12-27
|
10KB
|
386 lines
// µNote 1.1
// © 1996 by Daniel Hirscher
/// informaton
// -------------------------------------------------------------------------
//
// Projekt : µNote
//
// Dateiname : µNote
//
// Sprache/Compiler : C, MaxonC 3.1
//
// Betriebssystem : AmigaOS 3.1
//
// Kurzbeschreibung : kleines Programm um kleine Notizen zu machen
//
// zugehörige Dateien: µNote.guide
// µNote.c
//
// Ersteller : Daniel Hirscher
//
// Datum : 17.12.96 bis 27.12.96
//
// Version : siehe setapp();
//
// -------------------------------------------------------------------------
///
#define DEBUG
/// include
#include <my.h>
#include <exec/memory.h>
#include <clib/iffparse_protos.h>
#include <libraries/iffparse.h>
#include <pragma/iffparse_lib.h>
#include <gadgets/textfield.h>
#include <proto/textfield.h>
#include <intuition/icclass.h>
#include <intuition/gadgetclass.h>
#include "Note_cat.h"
///
/// define
#ifdef DEBUG
#define NOTEFILE "ram:µNotes.data"
#define NOTEBAK "ram:µNotes.bak"
#else
#define NOTEFILE "PROGDIR:µNotes.data"
#define NOTEBAK "PROGDIR:µNotes.bak"
#endif
#define HELPFILE "PROGDIR:µNote.guide"
#define DRUCKER "prt:"
///
/// var
APTR app;
// main-window
APTR wi_main;
Object *strip;
APTR show, sbar;
struct ClipboardHandle *clip_handle, *undo_handle;
// sonstiges
APTR aboutmui;
struct Library *IFFParseBase;
struct Library *TextFieldBase;
struct Library *LocaleBase;
Class *TextFieldClass;
///
/// hilfsfunktionen: xget, getstr
LONG xget(Object *obj, ULONG attribute)
{
LONG x;
get(obj,attribute,&x);
return(x);
}
char *getstr(Object *obj)
{
return((char *)xget(obj,MUIA_String_Contents));
}
///
/// myAbout
VOID myAbout()
{
MUI_RequestA(app,wi_main,NULL,GetNoteString(msgAboutTitle),GetNoteString(msgAboutButton),
GetNoteString(msgAbout),NULL);
}
static const struct Hook myAboutHook = { { NULL, NULL }, (VOID *)myAbout,NULL,NULL };
///
/// myAboutMUI
VOID myAboutMUI()
{
if (!aboutmui)
{
aboutmui = AboutmuiObject,
MUIA_Window_RefWindow, wi_main,
MUIA_Aboutmui_Application, app,
End;
}
if (aboutmui)
set(aboutmui,MUIA_Window_Open,TRUE);
else
DisplayBeep(0);
}
static const struct Hook myAboutMUIHook = { { NULL, NULL }, (VOID *)myAboutMUI,NULL,NULL };
///
/// myDrucken
VOID myDrucken()
{
int i,j;
BPTR fh;
char ch;
char *bu;
if (xget(show,TEXTFIELD_Size))
{
if ((fh = Open(DRUCKER,MODE_OLDFILE)))
{
FPuts(fh,"\n µNote\n\n ");
set(show,TEXTFIELD_ReadOnly,TRUE);
bu = (char *)xget(show,TEXTFIELD_Text);
j = 0;
for(i=0;i<xget(show,TEXTFIELD_Size);i++)
{
ch = bu[i];
if (j++>66)
{
FPutC(fh,'\n');
for (j=0;j<7;j++) FPutC(fh,' ');
j = 0;
}
FPutC(fh,ch);
if (ch == '\n')
{
for (j=0;j<7;j++) FPutC(fh,' ');
j = 0;
}
}
set(show,TEXTFIELD_ReadOnly,FALSE);
Close(fh);
}
}
}
static const struct Hook myDruckenHook = { { NULL, NULL }, (VOID *)myDrucken,NULL,NULL };
///
/// laden
void laden()
{
BPTR fh, lock;
char *cbuf;
long len;
struct FileInfoBlock *fib;
set(show,TEXTFIELD_Text,"");
if ((fib=AllocVec(sizeof(struct FileInfoBlock),MEMF_ANY)))
{
if ((lock = Lock(NOTEFILE,ACCESS_READ)))
{
Examine(lock,fib);
len = fib->fib_Size;
UnLock(lock);
}
FreeVec(fib);
}
fh = Open(NOTEFILE,MODE_OLDFILE);
if (fh)
{
if ((cbuf=AllocVec(len+1,MEMF_ANY)))
{
Seek(fh,0,OFFSET_BEGINNING);
Read(fh,cbuf,len);
cbuf[len] = NULL;
set(show,TEXTFIELD_Text,cbuf);
FreeVec(cbuf);
}
Close(fh);
}
set(show,TEXTFIELD_Modified,FALSE);
}
///
/// speichern
void speichern()
{
BPTR fh;
if (xget(show,TEXTFIELD_Modified) == TRUE)
{
DeleteFile(NOTEBAK); // altes .bak löschen
Rename(NOTEFILE,NOTEBAK); // datenfile zum .bak file machen
fh = Open(NOTEFILE,MODE_NEWFILE); // neues datenfile kreieren
if (fh)
{
Seek(fh,0,OFFSET_BEGINNING);
set(show,TEXTFIELD_ReadOnly,TRUE);
Write(fh, (char *)xget(show,TEXTFIELD_Text), xget(show,TEXTFIELD_Size) );
set(show,TEXTFIELD_ReadOnly,FALSE);
Close(fh);
}
set(show,TEXTFIELD_Modified,FALSE);
}
}
///
/// setapp
void setapp()
{
enum { men_about=1, men_amui, men_quit, men_mui, men_prt };
struct NewMenu my_menu[] =
{
{ NM_TITLE, "µNote", 0, 0, 0, 0 },
{ NM_ITEM, GetNoteString(msgMDrucken),GetNoteString(msgMDruckenSC), 0, 0, (APTR)men_prt },
{ NM_ITEM, NM_BARLABEL, 0, 0, 0, 0 },
{ NM_ITEM, GetNoteString(msgMAbout), "?", 0, 0, (APTR)men_about },
{ NM_ITEM, GetNoteString(msgMAboutM), 0, 0, 0, (APTR)men_amui },
{ NM_ITEM, NM_BARLABEL, 0, 0, 0, 0 },
{ NM_ITEM, GetNoteString(msgMQuit), "Q", 0, 0, (APTR)men_quit },
{ NM_TITLE, GetNoteString(msgMSettings), 0, 0, 0, 0 },
{ NM_ITEM, GetNoteString(msgMSettingsM), 0, 0, 0, (APTR)men_mui },
{ NM_END,NULL,0,0,0,0 }
};
app = ApplicationObject,
MUIA_Application_Title, "µNote",
MUIA_Application_Version, "$VER: µNote 1.1 (27.12.96)",
MUIA_Application_Copyright, "e-mailware",
MUIA_Application_Author, "Daniel Hirscher",
MUIA_Application_Description, GetNoteString(msgAppDesc),
MUIA_Application_Base, "MNOTE",
MUIA_Application_HelpFile, HELPFILE,
SubWindow, wi_main = WindowObject,
MUIA_Window_ID, MAKE_ID('M','A','I','N'),
MUIA_Window_Title, "µNote",
MUIA_Window_Menustrip, strip = MUI_MakeObject(MUIO_MenustripNM,my_menu,0),
WindowContents, VGroup,
Child, HGroup,
MUIA_Group_HorizSpacing, 0,
Child, show = BoopsiObject,
InputListFrame,
MUIA_Boopsi_Class, TextFieldClass,
MUIA_Boopsi_Smart, TRUE,
MUIA_Boopsi_MinWidth, 250,
MUIA_Boopsi_MinHeight, 100,
ICA_TARGET, ICTARGET_IDCMP,
TEXTFIELD_BlockCursor, TRUE,
TEXTFIELD_Partial, TRUE,
TEXTFIELD_ClipStream, clip_handle,
TEXTFIELD_UndoStream, undo_handle,
GA_TabCycle, TRUE,
MUIA_CycleChain, TRUE,
End,
Child, sbar = ScrollbarObject,
MUIA_CycleChain, TRUE,
MUIA_ShortHelp, GetNoteString(msgSchieber),
End,
End,
End,
End,
End;
}
///
/// setmethods
void setmethods()
{
// Notification
// menu
DoMethod((Object *)DoMethod(strip,MUIM_FindUData,men_quit),
MUIM_Notify,MUIA_Menuitem_Trigger,MUIV_EveryTime,
app,2,MUIM_Application_ReturnID,MUIV_Application_ReturnID_Quit);
DoMethod((Object *)DoMethod(strip,MUIM_FindUData,men_about),
MUIM_Notify,MUIA_Menuitem_Trigger,MUIV_EveryTime,
app,2,MUIM_CallHook,&myAboutHook);
DoMethod((Object *)DoMethod(strip,MUIM_FindUData,men_mui),
MUIM_Notify,MUIA_Menuitem_Trigger,MUIV_EveryTime,
app,2,MUIM_Application_OpenConfigWindow,NULL);
DoMethod((Object *)DoMethod(strip,MUIM_FindUData,men_amui),
MUIM_Notify,MUIA_Menuitem_Trigger,MUIV_EveryTime,
app,2,MUIM_CallHook,&myAboutMUIHook);
DoMethod((Object *)DoMethod(strip,MUIM_FindUData,men_prt),
MUIM_Notify,MUIA_Menuitem_Trigger,MUIV_EveryTime,
app,2,MUIM_CallHook,&myDruckenHook);
// main-window
DoMethod(show,MUIM_Notify,TEXTFIELD_Lines,MUIV_EveryTime,
sbar,3,MUIM_Set,MUIA_Prop_Entries,MUIV_TriggerValue);
DoMethod(show,MUIM_Notify,TEXTFIELD_Visible,MUIV_EveryTime,
sbar,3,MUIM_Set,MUIA_Prop_Visible,MUIV_TriggerValue);
DoMethod(show,MUIM_Notify,TEXTFIELD_Top,MUIV_EveryTime,
sbar,3,MUIM_NoNotifySet,MUIA_Prop_First,MUIV_TriggerValue);
DoMethod(sbar,MUIM_Notify,MUIA_Prop_First,MUIV_EveryTime,
show,3,MUIM_NoNotifySet,TEXTFIELD_Top,MUIV_TriggerValue);
}
///
/// setup
BOOL setup()
{
laden();
return(TRUE);
}
///
/// setdown
void setdown()
{
if (undo_handle) CloseClipboard(undo_handle);
if (clip_handle) CloseClipboard(clip_handle);
speichern();
if (TextFieldBase) CloseLibrary(TextFieldBase);
if (IFFParseBase) CloseLibrary(IFFParseBase);
CloseNoteCatalog();
CloseLibrary(LocaleBase);
}
///
/// openlib
void openlib()
{
LocaleBase = OpenLibrary("locale.library",38);
OpenNoteCatalog(NULL,NULL);
if (!(IFFParseBase = OpenLibrary("iffparse.library",0)))
fail(NULL,"iffparse.library not available\n");
clip_handle = OpenClipboard(0);
undo_handle = OpenClipboard(42);
if (!(TextFieldBase = OpenLibrary("gadgets/textfield.gadget",0)))
fail(NULL,"textfield boopsi gadget not available\n");
TextFieldClass = TEXTFIELD_GetClass();
}
///
/// main
int main(int argc, char *argv[])
{
init();
openlib();
setapp();
if (!app)
fail(app,"Failed to create Application.");
setmethods();
// ideal input-loop - DO NEVER CHANGE
DoMethod(wi_main,MUIM_Notify,MUIA_Window_CloseRequest,TRUE,
app,2,MUIM_Application_ReturnID,MUIV_Application_ReturnID_Quit);
if (!setup())
fail(app,"Failed to set up.");
set(wi_main,MUIA_Window_Open,TRUE);
{
ULONG sigs = 0;
while (DoMethod(app,MUIM_Application_NewInput,&sigs) != MUIV_Application_ReturnID_Quit)
{ if (sigs) { sigs = Wait(sigs | SIGBREAKF_CTRL_C); if (sigs & SIGBREAKF_CTRL_C) break; } }
}
set(wi_main,MUIA_Window_Open,FALSE);
setdown();
fail(app,NULL);
}
///
// end